﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Entity;

namespace DAL
{
    public class LanguageDAL : SqlDataProvider
    {
        #region[Language_GetById]
        public List<Language> Language_GetById(string Id)
        {
            List<Entity.Language> list = new List<Entity.Language>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Language_GetById", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Language.LanguageIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[Language_GetByAll]
        public List<Language> Language_GetByAll()
        {
            List<Entity.Language> list = new List<Entity.Language>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Language_GetByAll", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(Language.LanguageIDataReader(dr));
                    }
                }
                dr.Close();
            }
            return list;
        }
        #endregion
        #region[Language_Insert]
        public bool Language_Insert(Language data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Language_Insert", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", data.Id));
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Folder", data.Folder));
                dbCmd.Parameters.Add(new SqlParameter("@Default", data.Default));
                dbCmd.Parameters.Add(new SqlParameter("@Image", data.Image));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Language");
            return true;
        }
        #endregion
        #region[Language_Update]
        public bool Language_Update(Language data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Language_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", data.Id));
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Folder", data.Folder));
                dbCmd.Parameters.Add(new SqlParameter("@Default", data.Default));
                dbCmd.Parameters.Add(new SqlParameter("@Image", data.Image));
                dbCmd.Parameters.Add(new SqlParameter("@Active", data.Active));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Language");
            return true;
        }
        #endregion
        #region[Language_Delete]
        public bool Language_Delete(string Id)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Language_Delete", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Id", Id));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Language");
            return true;
        }
        #endregion

    }
}
